﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMK.PaketTracker.Server.Definitions;
using System.Data;
using System.Data.SqlClient;

namespace MMK.PaketTracker.Server.Database
{
    public class StationSqlDataLayer : BaseSqlDataLayer
    {
        public StationSqlDataLayer(string DbConnectionString) { this.Initialize(DbConnectionString); }

        public Station LoadStation(Guid stationID)
        {
            string sql = "SELECT * FROM [Stations] WHERE ID=@ID";

            using (IDataReader reader = this.GetDataReader(sql, new SqlParameter("@ID", stationID)))
            {
                return (reader.Read() ? LoadStationFromDataReader(reader) : null);
            }
        }

        private Station LoadStationFromDataReader(IDataReader reader)
        {
            Station station = new Station(this.GetGuid(reader, "ID"));
			station.Coordinate = new GPSCoordinate() { Latitude = this.GetDouble(reader, "Latitude"), Longitude = this.GetDouble(reader, "Longitude") };
            station.Name = this.GetString(reader, "Name");

            return station;
        }

    }
}
